home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / asy.c < prev    next >
C/C++ Source or Header  |  1992-05-28  |  5KB  |  208 lines

  1. /* @(#) $Header: asy.c,v 1.7 92/05/28 13:50:05 deyke Exp $ */
  2.  
  3. /* Generic serial line interface routines
  4.  * Copyright 1992 Phil Karn, KA9Q
  5.  */
  6. #include <stdio.h>
  7. #include "global.h"
  8. #include "config.h"
  9. #include "proc.h"
  10. #include "iface.h"
  11. #include "netuser.h"
  12. #include "slhc.h"
  13. #include "n8250.h"
  14. #include "asy.h"
  15. #include "ax25.h"
  16. #include "kiss.h"
  17. #include "nrs.h"
  18. #include "pktdrvr.h"
  19. #include "slip.h"
  20. /* #include "ppp.h" */
  21. #include "commands.h"
  22.  
  23. /* Attach a serial interface to the system
  24.  * argv[0]: hardware type, must be "asy"
  25.  * argv[1]: I/O address, e.g., "0x3f8"
  26.  * argv[2]: vector, e.g., "4"
  27.  * argv[3]: mode, may be:
  28.  *              "slip" (point-to-point SLIP)
  29.  *              "ax25" (AX.25 frame format in SLIP for raw TNC)
  30.  *              "nrs" (NET/ROM format serial protocol)
  31.  *              "ppp" (Point-to-Point Protocol, RFC1171, RFC1172)
  32.  * argv[4]: interface label, e.g., "sl0"
  33.  * argv[5]: receiver ring buffer size in bytes
  34.  * argv[6]: maximum transmission unit, bytes
  35.  * argv[7]: interface speed, e.g, "9600"
  36.  * argv[8]: optional flags,
  37.  *              'v' for Van Jacobson TCP header compression (SLIP only,
  38.  *                  use ppp command for VJ compression with PPP);
  39.  */
  40. int
  41. asy_attach(argc,argv,p)
  42. int argc;
  43. char *argv[];
  44. void *p;
  45. {
  46.     register struct iface *ifp;
  47.     struct asy *asyp;
  48.     char *ifn;
  49.     int dev;
  50.     int xdev;
  51.     int trigchar = -1;
  52.     char monitor = FALSE;
  53. #if     defined(SLIP) || defined(AX25)
  54.     struct slip *sp;
  55. #endif
  56. #ifdef  NRS
  57.     struct nrs *np;
  58. #endif
  59.  
  60.     if(if_lookup(argv[4]) != NULLIF){
  61.         printf("Interface %s already exists\n",argv[4]);
  62.         return -1;
  63.     }
  64.     /* Find unused asy control block */
  65.     for(dev=0;dev < ASY_MAX;dev++){
  66.         asyp = &Asy[dev];
  67.         if(asyp->iface == NULLIF)
  68.             break;
  69.     }
  70.     if(dev >= ASY_MAX){
  71.         printf("Too many asynch controllers\n");
  72.         return -1;
  73.     }
  74.  
  75.     /* Create interface structure and fill in details */
  76.     ifp = (struct iface *)callocw(1,sizeof(struct iface));
  77.     ifp->addr = Ip_addr;
  78.     ifp->name = strdup(argv[4]);
  79.     ifp->mtu = atoi(argv[6]);
  80.     ifp->dev = dev;
  81.     ifp->stop = asy_stop;
  82.  
  83. #ifdef  SLIP
  84.     if(stricmp(argv[3],"SLIP") == 0) {
  85.         for(xdev = 0;xdev < SLIP_MAX;xdev++){
  86.             sp = &Slip[xdev];
  87.             if(sp->iface == NULLIF)
  88.                 break;
  89.         }
  90.         if(xdev >= SLIP_MAX) {
  91.             printf("Too many slip devices\n");
  92.             return -1;
  93.         }
  94.         setencap(ifp,"SLIP");
  95.         ifp->ioctl = asy_ioctl;
  96.         ifp->raw = slip_raw;
  97.         ifp->show = slip_status;
  98.         ifp->flags = 0;
  99.         ifp->xdev = xdev;
  100.  
  101.         sp->iface = ifp;
  102.         sp->send = asy_send;
  103.         sp->get = get_asy;
  104.         sp->type = CL_SERIAL_LINE;
  105.         trigchar = FR_END;
  106. #ifdef VJCOMPRESS
  107.         if((argc > 8) && (strchr(argv[8],'v') != NULLCHAR)) {
  108.             sp->escaped |= SLIP_VJCOMPR;
  109.             sp->slcomp = slhc_init(16,16);
  110.         }
  111. #else
  112.         sp->slcomp = NULL;
  113. #endif  /* VJCOMPRESS */
  114.         ifp->rxproc = asy_rx;
  115.     } else
  116. #endif
  117. #ifdef  AX25
  118.     if(stricmp(argv[3],"AX25") == 0) {
  119.         /* Set up a SLIP link to use AX.25 */
  120.         for(xdev = 0;xdev < SLIP_MAX;xdev++){
  121.             sp = &Slip[xdev];
  122.             if(sp->iface == NULLIF)
  123.                 break;
  124.         }
  125.         if(xdev >= SLIP_MAX) {
  126.             printf("Too many slip devices\n");
  127.             return -1;
  128.         }
  129.         setencap(ifp,"AX25");
  130.         ifp->ioctl = kiss_ioctl;
  131.         ifp->raw = kiss_raw;
  132.         ifp->show = slip_status;
  133.  
  134.         if(ifp->hwaddr == NULLCHAR)
  135.             ifp->hwaddr = mallocw(AXALEN);
  136.         memcpy(ifp->hwaddr,Mycall,AXALEN);
  137.         ifp->xdev = xdev;
  138.  
  139.         sp->iface = ifp;
  140.         sp->send = asy_send;
  141.         sp->get = get_asy;
  142.         sp->type = CL_KISS;
  143.         trigchar = FR_END;
  144.         ifp->rxproc = asy_rx;
  145.     } else
  146. #endif
  147. #ifdef  NRS
  148.     if(stricmp(argv[3],"NRS") == 0) {
  149.         /* Set up a net/rom serial iface */
  150.         for(xdev = 0;xdev < SLIP_MAX;xdev++){
  151.             np = &Nrs[xdev];
  152.             if(np->iface == NULLIF)
  153.                 break;
  154.         }
  155.         if(xdev >= SLIP_MAX) {
  156.             printf("Too many nrs devices\n");
  157.             return -1;
  158.         }
  159.         /* no call supplied? */
  160.         setencap(ifp,"AX25");
  161.         ifp->ioctl = asy_ioctl;
  162.         ifp->raw = nrs_raw;
  163.  
  164.         ifp->hwaddr = mallocw(AXALEN);
  165.         memcpy(ifp->hwaddr,Mycall,AXALEN);
  166.         ifp->xdev = xdev;
  167.         np->iface = ifp;
  168.         np->send = asy_send;
  169.         np->get = get_asy;
  170.         trigchar = ETX;
  171.         ifp->rxproc = nrs_recv;
  172.     } else
  173. #endif
  174. #ifdef  PPP
  175.     if(stricmp(argv[3],"PPP") == 0) {
  176.         /* Setup for Point-to-Point Protocol */
  177.         trigchar = HDLC_FLAG;
  178.         monitor = TRUE;
  179.         setencap(ifp,"PPP");
  180.         ifp->ioctl = asy_ioctl;
  181.         ifp->flags = FALSE;
  182.  
  183.         /* Initialize parameters for various PPP phases/protocols */
  184.         if (ppp_init(ifp) != 0) {
  185.             printf("Cannot allocate PPP control block\n");
  186.             free(ifp->name);
  187.             free((char *)ifp);
  188.             return -1;
  189.         }
  190.     } else
  191. #endif
  192.     {
  193.         printf("Mode %s unknown for interface %s\n",
  194.             argv[3],argv[4]);
  195.         free(ifp->name);
  196.         free(ifp);
  197.         return -1;
  198.     }
  199.  
  200.     /* Link in the interface */
  201.     ifp->next = Ifaces;
  202.     Ifaces = ifp;
  203.  
  204.     asy_init(dev,ifp,argv[1],argv[2],(int16)atol(argv[5]),
  205.         trigchar,monitor,(int16)atol(argv[7]));
  206.     return 0;
  207. }
  208.